version 16.1
clear all
cd "MYPATH\derived\make_waves"
adopath + ../../ado/

cap log close
log using build.log, replace

preliminaries
foreach PATH in RESULTS TEMP {
	cap mkdir "${`PATH'}\derived\make_waves"
    if "`PATH'" != "TEMP" cap mkdir "${`PATH'}\derived\make_waves\figures"
}

graph set window fontface default
graph set ps fontface default
graph set window fontfacemono "Consolas"
graph set ps fontfacemono "Consolas"

program main
	build_waves
end

program build_waves
	use "MYPATH\MYPATH.dta", clear
	collapse (firstnm) year, by(lan)
	drop year 
	di "Wave 2"
	gen wave2 = ym(2005,6) if lan == 1
	replace wave2 = ym(2010, 1) if lan == 3
	replace wave2 = ym(2012, 1) if lan == 4
	replace wave2 = ym(2007, 1) if lan == 5
	replace wave2 = ym(2009, 4) if lan == 6
	replace wave2 = ym(2012, 3) if lan == 7
	replace wave2 = ym(2012, 1) if lan == 8
	replace wave2 = ym(2005, 1) if lan == 9
	replace wave2 = ym(2008, 1) if lan == 10
	replace wave2 = ym(2008, 1) if lan == 12
	replace wave2 = ym(2017, 5) if lan == 13
	replace wave2 = ym(2008, 2) if lan == 14
	replace wave2 = ym(2010, 3) if lan == 17
	replace wave2 = ym(2008, 11) if lan == 18
	replace wave2 = ym(2017, 2) if lan == 19
	replace wave2 = ym(2011, 1) if lan == 20
	replace wave2 = ym(2008, 1) if lan == 21
	replace wave2 = ym(2012, 3) if lan == 22
	replace wave2 = ym(2009, 1) if lan == 23
	replace wave2 = ym(2009, 10) if lan == 24
	replace wave2 = ym(3000, 1) if lan == 25  // Norrbotten never introduced KUB
	format wave2 %tmMon_YY
	
	di "Wave 3"
	gen wave3 = ym(2016, 10) if lan == 1
	replace wave3 = ym(2016, 9) if lan == 3
	replace wave3 = ym(2017, 1) if lan == 4
	replace wave3 = ym(2016, 1) if lan == 5
	replace wave3 = ym(2018, 6) if lan == 6
	replace wave3 = ym(2017, 5) if lan == 7
	replace wave3 = ym(2017, 9) if lan == 8
	replace wave3 = ym(2016, 1) if lan == 9
	replace wave3 = ym(2016, 6) if lan == 10
	replace wave3 = ym(2017, 5) if lan == 12
	replace wave3 = ym(2017, 5) if lan == 13
	replace wave3 = ym(2017, 1) if lan == 14
	replace wave3 = ym(2018, 4) if lan == 17
	replace wave3 = ym(2018, 10) if lan == 18
	replace wave3 = ym(2017, 2) if lan == 19
	replace wave3 = ym(2017, 11) if lan == 20
	replace wave3 = ym(2017, 1) if lan == 21
	replace wave3 = ym(2017, 9) if lan == 22
	replace wave3 = ym(2017, 9) if lan == 23
	replace wave3 = ym(3000, 1) if lan == 24  // Vasterbotten never introduced NIPT
	replace wave3 = ym(3000, 1) if lan == 25  // Norrbotten never introduced NIPT
	format wave3 %tmMon_YY
	
	rename wave2 wave2_intro
	rename wave3 wave3_intro
	
	save $DATA\waves.dta, replace
end


* Execute
main
